define(function(require, exports, module){
	require("resource/js/easyui/themes/icon.css");
	require("resource/js/easyui/easyloader.js");
	var AJAX = require("resource/js/component/ajax.js");
	var EUtil = require("resource/js/component/easyutil.js");
	var ECombobox = require("resource/js/component/easycombobox.js");
	ECombobox.create({
		url:BASEPATH+"/base/authoriza/basecode/getType.htm",
		param:{checkeds:"DCS_vehicleCode,DCS_constructionVehicleState"}
	})
	var dgutil = undefined;
	var config = {
			name:"车辆运输轨迹",
			column:[[
                    {field:'id',title:'主键ID',width:100,align:'center',height:50,hidden:true},
                    
                    {field:'sectionId',title:'标段ID',width:100,align:'center',height:50,hidden:true},
                    
                    {field:'deviceVid',title:'设备编号',width:100,align:'center',height:50,hidden:false},
                    
                    {field:'vehicleName',title:'车牌号',width:100,align:'center',height:50,hidden:false},
                    
				    {field:'vehicleTypeText',title:'联系人',width:100,align:'center',height:50,hidden:false},
				    
			    	{field:'vehicleType',title:'联系电话',width:100,align:'center',height:50,hidden:true},
			    	
			    	{field:'frdRemark',title:'平均时速(km/h)',width:100,align:'center',height:50,hidden:false},
                    
                    {field:'workAreaId',title:'最高时速(km/h)',width:100,align:'center',height:50,hidden:false},
                    
                    {field:'startTime',title:'时间',width:100,align:'center',height:50,hidden:false},
                    
                    {field:'updateUser',title:'查看行驶路程',width:100,align:'center',height:50,hidden:false},
                    
                    ]]
	}
	
	var initpage = function(){
			dgutil = EUtil.ajaxDataGrid(datagridconfig);
			ECombobox.init({ ele:"#vehicleType_search", grouptype:"DCS_vehicleCode"});
            ECombobox.init({ ele:"#state_search", grouptype:"DCS_constructionVehicleState"});
		}
	var initFiledByForm = function(rows,id){
		var validate = true;
		if(typeof rows == "boolean"){
			validate = rows;
		}
		ECombobox.init({ ele:"#vehicleType_"+id, grouptype:"DCS_vehicleCode",value:(validate?rows.vehicleType:'')
		});
        ECombobox.init({ ele:"#state_"+id, grouptype:"DCS_constructionVehicleState",value:(validate?rows.state:'')
        });
	}

	var addDialogInit = function(url){
		$("#editdlg").dialog({
			title:config.name+"增加",
			href:url,
			onLoad:function(){
				initFiledByForm(false,'add');
		    },
			buttons: [{
				text:'保存',
				iconCls:'icon-ok',
				accessKey:{akey:18,mkey:83},
				handler:function(){
					using(["form"],function(){
						if($("#editform").form("validate")){
							var obj = $("#editform").serializeJson();
							AJAX.init().success(function(code,msg,data){
								$.messager.show({ title:"系统提示", msg:msg, timeout:2000, showType:'slide' });
								dgutil.pager();
								$("#editdlg").dialog("close");
		    	    		}).error(function(code,msg,data){
		    	    			$.messager.alert("系统提示", msg, "error");
		    	    		}).contentType('application/json').post(BASEPATH+"/dcs/sys/constructionVehicle/saveSysConstructionVehicle.htm",JSON.stringify(obj));
						}
					});
				}
			},{
				text:'取消',
				addClass:'l-btn-red',iconCls:'icon-not',
				accessKey:{akey:18,mkey:67},
				handler:function(){
					$('#editdlg').dialog('close');
				}
			}]
		});
		$("#editdlg").dialog("open");
	}
	var updDialogInit = function(url,row){
		$("#editdlg").dialog({
			iconCls: 'icon-save',
			title:config.name+'修改',
			href:url,
			onLoad:function(){
				initFiledByForm(row,'upd');
				$("#editform").form("load",row);
		    },
			buttons: [{
				text:'保存',
				iconCls:'icon-ok',
				accessKey:{akey:18,mkey:83},
				handler:function(){
					using(["form"],function(){
						if($("#editform").form("validate")){
							var obj = $("#editform").serializeJson();
							AJAX.init().success(function(code,msg,data){
								$.messager.show({ title:"系统提示", msg:msg, timeout:2000, showType:'slide' });
								dgutil.pager();
								$("#editdlg").dialog("close");
		    	    		}).error(function(code,msg,data){
		    	    			$.messager.alert("系统提示", msg, "error");
		    	    		}).contentType('application/json').post(BASEPATH+'/dcs/sys/constructionVehicle/updateSysConstructionVehicle.htm',JSON.stringify(obj));
						}
					});
				}
			},{
				text:'取消',
				addClass:'l-btn-red',iconCls:'icon-not',
				accessKey:{akey:18,mkey:67},
				handler:function(){
					$('#editdlg').dialog('close');
				}
			}]
		});
		$("#editdlg").dialog("open");
	}
	var delInit = function(url,rows){
		var checks = [];
		for(var key in rows){
			var id = '' +rows[key].id;
			checks.push(id);
		}
		EUtil.ajaxHandler(url,{checkeds:checks.join(",")},function(){
			dgutil.delRow(rows);
		});
	}
	module.exports = {
			trans:function(){
				var buttons={
						title:{
							_class:"",
							text:"车辆运输轨迹列表"
							
						},
						btn:[{
								 iconCls:"icon-search",
								 text:"查询",
								 //addClass:"l-btn-display",
								 url:"/dcs/water/waterAlarm/queryWaterAlarmByPage.htm",
								 handler: function(){dgutil.pager(1);}
						     }
						]};
				datagridconfig = {
						fitColumns:true,
						singleSelect:false,
						striped:true,
						autoRowHeight:false,
						fit: true,
						toolbar:buttons,
						columns:config.column,
						eid:"dg",
						url:BASEPATH+'/dcs/sys/constructionVehicle/querySysConstructionVehicleByPage.htm',
						args:"searchform"
				};
				
				using(["parser","dialog","datagrid" ,"combo","combobox"],function(){
					initpage();
				});
			}
	}
});
